package com.ljx.offer;

import org.junit.Test;

import java.util.LinkedList;

/**
 * @author 李捷禧
 * Date: 2023/3/10
 * ClassName: task01
 */

public class CQueue {


        private LinkedList<Integer> s1;
        private LinkedList<Integer> s2;

        public CQueue() {
            s1 = new LinkedList<>();
            s2 = new LinkedList<>();
        }

        public void appendTail(int value) {
            s1.addLast(value);
        }

        public int deleteHead() {
            if(!s2.isEmpty()){
               return s2.removeLast();
            }else if(s1.isEmpty()){
                return -1;
            }while(!s1.isEmpty()){
                s2.addLast(s1.removeLast());
            }
            return s2.removeLast();
        }



        @Test
    public void test(){
            CQueue cQueue = new CQueue();
            cQueue.appendTail(2);
            cQueue.appendTail(5);
            cQueue.appendTail(7);
            System.out.println(cQueue.deleteHead());
            System.out.println(cQueue.deleteHead());
            System.out.println(cQueue.deleteHead());
            System.out.println(cQueue.deleteHead());
        }
}
